﻿using System;
using System.Collections.Generic;
using System.IO;
using Autodesk.Revit.DB;
using YArchitech.LIB;
using YArchitech.Revit;

namespace HYLightingEquipmentLay.CommonUtils
{
	public class FamilyPathManager
	{
		public static string GetSmokeFamilyFullPath()
		{
			string path = "FireDetector\\感烟火灾探测器_吸顶.rfa";
			return Path.Combine(Product.FamilyLocation, RevitVersion.Version, path);
		}

		public static FamilySymbol LoadFamily(Autodesk.Revit.DB.Document doc, string strFamilyPath, string strFamilyName)
		{
			if (!File.Exists(strFamilyPath))
			{
				return null;
			}
			Family family = null;
			if (!doc.LoadFamily(strFamilyPath, out family) || family == null)
			{
				return null;
			}
			if (family != null && family.GetSymbols() != null)
			{
				using (List<FamilySymbol>.Enumerator enumerator = family.GetSymbols().GetEnumerator())
				{
					if (enumerator.MoveNext())
					{
						FamilySymbol familySymbol = enumerator.Current;
						if (Convert.ToInt32(RevitVersion.Version) > 2015)
						{
							familySymbol.Activate();
						}
						return familySymbol;
					}
				}
			}
			return null;
		}
	}
}
